package com.zmcc.utils;

import com.google.gson.Gson;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.HashMap;
import java.util.Map;

public class WrapperUtils {
    public static String authHeader(String appkey, String appsecret) {
        long currentTime = System.currentTimeMillis();
        StringBuffer buffer = new StringBuffer(appkey);
        String signStr = DigestUtils.md5Hex(buffer.append(appsecret).append(currentTime).toString());
        Gson gson = new Gson();
        Map<String, Object> map = new HashMap<>();
        map.put("apiKey", appkey);
        map.put("time",currentTime);
        map.put("sign", signStr);
        return Base64.encodeBase64String(gson.toJson(map).toString().getBytes());
    }

    public static Map<String, String> authHeaderToMap(String header) {
        Map<String, String> map = new HashMap<>();
        map.put("Authorization", header);
        return map;
    }
}
